package com.zxb.core.util;

import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

import cn.hutool.core.img.ImgUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.asymmetric.Sign;
import cn.hutool.crypto.asymmetric.SignAlgorithm;
import cn.hutool.crypto.digest.HmacAlgorithm;
import cn.hutool.extra.pinyin.PinyinUtil;

/**
 * @author Zxb
 */
public class HutoolUtil {
	public static void main(String[] args) {
		//随机数
		RandomUtil.randomString(6);
		RandomUtil.randomInt(1, 100);
		//汉语拼音
		PinyinUtil.getPinyin("张晓波");
		//摘要
		SecureUtil.md5("123456");
		SecureUtil.sha1("123456");
		SecureUtil.hmac(HmacAlgorithm.HmacMD5, "123456");
		SecureUtil.hmacMd5("123456");
		SecureUtil.hmacSha1("123456");

		byte[] data = "我是一段测试字符串".getBytes();
		Sign sign = SecureUtil.sign(SignAlgorithm.MD5withRSA);
		//签名
		byte[] signed = sign.sign(data);
		//验证签名
		sign.verify(data, signed);

		//图片压缩
		ImgUtil.scale(new File("e:/src.jpg"), new File("e:/dest.jpg"), 0.5f);
		//图片裁剪
		ImgUtil.cut(new File("e:/src.jpg"), new File("e:/dest.jpg"), new Rectangle(200, 200, 100, 100));
		//rotate 旋转图片
		BufferedImage image;
		try {
			image = (BufferedImage) ImgUtil.rotate(ImageIO.read(new File("e:/src.jpg")), 180);
			ImgUtil.write(image, new File("e:/dest.jpg"));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
